<template>
  <div>
    <el-form :inline="true" :model="searchForm" size="mini">
      <div class="common-btn">
        <el-button type="primary" size="mini" @click="exportExcelChild">导出excel</el-button>

      </div>
      <div class="search-common">
        <el-row :gutter="10">
          <el-col :sm="6">
            <div class="grid-content bg-purple">
              <el-form-item label="订单类型">
                <el-select placeholder="" v-model="searchForm.type" style="width:180px">
                  <el-option label="全部" value=""></el-option>
                  <el-option label="购买课程" value="1"></el-option>
                  <el-option label="购买短信" value="2"></el-option>
                  <el-option label="打赏课程" value="3"></el-option>
                  <el-option label="打赏视频" value="4"></el-option>
                  <el-option label="打赏直播" value="5"></el-option>

                </el-select>
              </el-form-item>
            </div>
          </el-col>

          <el-col :sm="6">

            <div class="grid-content bg-purple-light">
              <el-form-item label="订单来源">
                <el-select placeholder="来源" v-model="searchForm.source" style="width:180px">
                  <el-option label="全部" value=""></el-option>
                  <el-option label="PC" value="1"></el-option>
                  <el-option label="Android" value="2"></el-option>
                  <el-option label="IOS" value="3"></el-option>
                  <el-option label="WEB" value="4"></el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :sm="6">
            <el-form-item label="经纪商">
              <el-select v-model="searchForm.agent_num" placeholder="请选择经纪商">
                <el-option label="全部" value=""></el-option>
                <el-option v-for="item of getAngents" :key="item.key" :label="item.name" :value="item.key"></el-option>

              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="10">
          <el-col :sm="6">
            <el-form-item label="退款状态">
              <el-select placeholder="交易状态" v-model="searchForm.refund_status" style="width:180px">
                <el-option label="全部" value=""></el-option>
                <el-option label="未退款" value="1"></el-option>
                <el-option label="退款中" value="2"></el-option>
                <el-option label="已退款" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :sm="6">
            <el-form-item label="">
              <el-input placeholder="请输入内容" v-model="searchForm.recode_name" class="input-with-select">
                <el-select v-model="searchForm.recode_select" slot="prepend" placeholder="请选择" style="width:100px;">
                  <el-option label="用户手机" value="1"></el-option>
                  <el-option label="用户ID" value="2"></el-option>
                  <el-option label="用户昵称" value="3"></el-option>
                  <el-option label="课程ID" value="4"></el-option>
                  <el-option label="视频ID" value="5"></el-option>
                  <el-option label="直播ID" value="6"></el-option>
                </el-select>
              </el-input>
            </el-form-item>

          </el-col>

          <el-col :sm="6">
            <el-form-item label="订单数额">
              <el-input v-model="searchForm.startpearl" placeholder="请输入数值" controls-position="right" style="width:100px"></el-input>
              至
              <el-input v-model="searchForm.endpearl" placeholder="请输入数值" controls-position="right" style="width:100px"></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>

          <el-col :xs="24">
            <el-form-item label="订单时间">
              <el-date-picker v-model="searchForm.orderTime" :picker-options="pickerOptions" type="daterange" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :sm="24" :lg="6" :xs="24">
            <el-form-item>
              <el-button type="primary" @click="searchFromChild">查询</el-button>
              <el-button type="info" @click="resetForm">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      searchForm: {
        type: "",
        refund_status: "",
        source: "",
        recode_select: "1",
        orderTime: "",
        agent_num: "",
        recode_name: "",
        startpearl: "",
        endpearl: ""
      },
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        }
      }

    };
  },
  created() {
    this.$store.dispatch("setAllAngentLists");
  },
  computed: {
    ...mapGetters({
      getAngents: "getAllAngentLists"
    })
  },
  mounted() { },
  methods: {
    //到处excel
    exportExcelChild() {
      this.$emit(
        "exportexcel",
        Object.assign({}, this.commonParams(), this.searchForm)
      );
    },
    //退款
    backMoneyChild() {
      this.$emit("backmoney", 2);
    },
    //查询
    commonParams() {
      let reg = /\d/;
      return {
        startTime: this.searchForm.orderTime ? this.searchForm.orderTime[0] : "",
        endTime: this.searchForm.orderTime ? this.searchForm.orderTime[1] : "",
        account:
          this.searchForm.recode_select == 1 ? this.searchForm.recode_name : "",
        user_num:
          this.searchForm.recode_select == 2 ? this.searchForm.recode_name : "",
        nickname:
          this.searchForm.recode_select == 3 ? this.searchForm.recode_name : "",
        course_num:
          this.searchForm.recode_select == 4 ? this.searchForm.recode_name : "",
        broadcast_num:
          this.searchForm.recode_select == 6 ? this.searchForm.recode_name : "",
        flash_num:
          this.searchForm.recode_select == 5 ? this.searchForm.recode_name : ""
      };
    },
    searchFromChild() {
      let params = Object.assign({}, this.commonParams(), this.searchForm);
      console.log(params);
      this.$emit("searchform", params);
    },
    resetForm() {
      this.searchForm = {
        type: "",
        refund_status: "",
        source: "",
        recode_select: "1",
        orderTime: "",
        agent_num: "",
        recode_name: "",
        startpearl: "",
        endpearl: ""
      };
    }
  }
};
</script>
<style scoped></style>
